盒子
盒子

Benchmark of parallel sort in boost and ppl

VS 执行的时候的时间差距很大,不知道为甚?直接执行100000000个随机数排序的状态下,boostppl里面的差距在0.5秒以内。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#include <iostream>
#include <algorithm>
#include <random>
#include <cstdlib>
#include <vector>
#include <ppl.h>
#include <boost/sort/parallel_stable_sort/parallel_stable_sort.hpp>
#include <chrono>
#include <ctime>
int main()
{
uint32_t NELEM = 100000000;
std::mt19937 my_rand(0);
std::vector< uint64_t > A, B;
A.reserve(NELEM);
for (uint32_t i = 0; i < NELEM; ++i)
{
A.push_back(my_rand());
// std::cout << A[i] << std::endl;
}
auto start = std::chrono::system_clock::now();
auto end = std::chrono::system_clock::now();
auto elapsed_seconds = end - start;
B = A;
start = std::chrono::system_clock::now();
boost::sort::parallel_stable_sort(B.begin(), B.end());
end = std::chrono::system_clock::now();
elapsed_seconds = end - start;
std::cout << "boost::sort::parallel_stable_sort elapsed time: " << std::chrono::duration<double>(elapsed_seconds).count() << "s\n";
B = A;
start = std::chrono::system_clock::now();
concurrency::parallel_sort(B.begin(), B.end());
end = std::chrono::system_clock::now();
elapsed_seconds = end - start;
std::cout << "concurrency::parallel_sort elapsed time: " << std::chrono::duration<double>(elapsed_seconds).count() << "s\n";
B = A;
start = std::chrono::system_clock::now();
std::sort(B.begin(), B.end());
end = std::chrono::system_clock::now();
elapsed_seconds = end - start;
std::cout << "std::sort elapsed time: " << std::chrono::duration<double>(elapsed_seconds).count() << "s\n";
return 0;
}

呼呼呼山(http://code4fun.me)
2019-04-19 17:50:41